package approval.dao;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import models.util.MySqlDataAccessHelper;

import resource.pojo.Typedoc;

public class TypeDocDAO {
	public static ArrayList<Typedoc> getAllTypeDoc(){
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		ArrayList<Typedoc> lst = new ArrayList<Typedoc>();
		CallableStatement cs = null;
		try{
			mysql.open();
			cs = mysql.getConnection().prepareCall("call sp_getAllTypeDoc");
			ResultSet rs = cs.executeQuery();
			while(rs.next()){
				lst.add(new Typedoc(rs.getInt("IDTypeDoc"),
						rs.getString("TypeName"), rs.getInt("IDContentDoc"),
						rs.getInt("IDTemplate"),
						rs.getInt("IDConfigStaticLang"),
						rs.getString("Description"),rs.getDate("timecreate"),rs.getInt("views")));
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			mysql.close();
			try {
				cs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		lst.remove(7);
		return lst;
	}
	
	// TODO hongmophi
	public static ArrayList<Typedoc> getAllTypeDocMo(){
		ArrayList<Typedoc> lstType = new ArrayList<Typedoc>();
		MySqlDataAccessHelper help = new MySqlDataAccessHelper();
		try {
			help.open();
			String sql = "select * from typedoc";
			ResultSet rs = help.executeQuery(sql);
			while(rs.next()){
				lstType.add(new Typedoc(rs.getInt("IDTypeDoc"),
						rs.getString("TypeName"), rs.getInt("IDContentDoc"),
						rs.getInt("IDTemplate"),
						rs.getInt("IDConfigStaticLang"),
						rs.getString("Description"),rs.getDate("timecreate"),rs.getInt("views")));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			help.close();
		}
		
		return lstType;
	}
}
